function tblClear() {
	var table = document.getElementById('full-table');
	table.parentNode.removeChild(table);
}

function resetFilters(filter) {
	filter.selectedIndex = 0;
}

function resetAll() {
	var filter = document.getElementById('gender');
	filter.selectedIndex = 0;
	var filter = document.getElementById('grad');
	filter.selectedIndex = 0;
	
	var ajaxReq;
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxReq = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxReq = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxReq = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				return false;
			}
		}
	}
	ajaxReq.onreadystatechange = function(){
		if(ajaxReq.readyState == 4){
			try {
				tblClear();
			} catch (err) {
				console.log('Error: #full-table already removed?');
			}
			document.getElementById('results').innerHTML = ajaxReq.responseText;
		}
	}
		
	var selected = document.getElementById('grad');
	var selGrad = selected.options[selected.selectedIndex].value;
	ajaxReq.open("GET", "filter_process.php", true);
	ajaxReq.send(null);
}

function ajaxGenderFilter(){
	var ajaxReq;
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxReq = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxReq = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxReq = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				return false;
			}
		}
	}
	ajaxReq.onreadystatechange = function(){
		if(ajaxReq.readyState == 4){
			try {
				tblClear();
			} catch (err) {
				console.log('Error: #full-table already removed?');
			}
			document.getElementById('results').innerHTML = ajaxReq.responseText;
		}
	}
	var selected = document.getElementById('gender');
	var selGender = selected.options[selected.selectedIndex].value;
	ajaxReq.open("GET", "filter_process.php?gender=" + selGender, true);
	ajaxReq.send(null);
	
	// reset other filter
	var otherSelect = document.getElementById('grad');
	resetFilters(otherSelect);
}

function ajaxGradFilter(){
	var ajaxReq;
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxReq = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxReq = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxReq = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				return false;
			}
		}
	}
	ajaxReq.onreadystatechange = function(){
		if(ajaxReq.readyState == 4){
			try {
				tblClear();
			} catch (err) {
				console.log('Error: #full-table already removed?');
			}
			document.getElementById('results').innerHTML = ajaxReq.responseText;
		}
	}
	var selected = document.getElementById('grad');
	var selGrad = selected.options[selected.selectedIndex].value;
	ajaxReq.open("GET", "filter_process.php?grad=" + selGrad, true);
	ajaxReq.send(null);
	
	// reset other filter
	var otherSelect = document.getElementById('gender');
	resetFilters(otherSelect);
}